package cn.itcast.web.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义异常类，当控制器方法出现异常时候会自动来到这里
 */
@Component
public class CustomException implements HandlerExceptionResolver{
    @Override
    public ModelAndView resolveException(
            HttpServletRequest request,
            HttpServletResponse response,
            Object handler, Exception ex) {
        ex.printStackTrace();
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/error");
        mv.addObject("errorMsg","系统忙，请联系管理员!");
        return mv;
    }
}
